/* eslint-disable no-param-reassign */
/* eslint-disable max-lines */
import * as BASE from '@/stores/definitions-base';
import { DatePicker2, DatePicker, Input, Switch } from '@alifd/next';
import { t } from '@lingui/macro';
import React from 'react';

const {
  DATETIME_TEXT,
  DATE_TEXT,
  TIME_TEXT,
  EMPTY_TEXT,
  ENUMS: ENUMSBase,
  FieldsGrid: FieldGridBase,
  TitleGrid,
  column: columnBase,
  toSelectDataSource,
} = BASE;
export { DATETIME_TEXT, DATE_TEXT, EMPTY_TEXT, TIME_TEXT, TitleGrid, toSelectDataSource };

export function column(...args) {
  return columnBase(orderModel, ...args);
}

export function FieldsGrid(props) {
  return <FieldGridBase model={orderModel} {...props} />;
}

//----------------------------------------------------------------------
export const ENUMS = {
  ...ENUMSBase,
  ticketStatus: {
    0: t`已取消`,
    1: t`未乘车`,
    2: t`已乘车`,
    3: t`已完成`,
    4: t`状态未知`,
    5: t`已过期`,
  },
  orderStatus: {
    0: t`已取消`,
    1: t`已支付`,
    2: t`已完成`,
    3: t`其他`,
  },
  payType: {
    0: t`微信`,
    1: t`支付宝`,
  },
  orderFromType: {
    0: t`微信`,
    1: t`后台`,
    2: t`H5下单`,
  },
  state: {
    0: '已驳回',
    1: '申请中',
    2: '已提交',
  },
  type: {
    0: '车票类型',
    1: '取消订单',
    2: '其他类型',
  },
};

export const MAGIC_NUMBERS = {
  ticketState: {
    NOT_IN_CAR: 1,
    // 0-已取消 1-未乘车 2-已乘车 3-已完成 4-其他 5-已过期
  },
};

export const orderModel = {
  cancelCoupon: {
    label: t`是否取消卡券`,
    ui: {
      renderer: (v, r) => <Switch checked={v} disabled={JSON.stringify(r.discountInfos) === '[]'} unCheckedChildren="否" checkedChildren="是" autoWidth />,
    },
  },
  discountPrice: {
    label: '优惠金额',
    ui: {
      renderer: (v) => <span>{v}</span>,
    },
  },
  actualPrice: {
    label: '实付价格',
    ui: {
      renderer: (v) => <span>{v}</span>,
    },
  },
  cancelOrder: {
    label: t`是否取消订单`,
    ui: {
      renderer: (v) => <Switch checked={v} unCheckedChildren="否" checkedChildren="是" autoWidth />,
    },
  },
  enableProfitShare: {
    label: '是否开启分账',
    ui: {
      renderer: (v) => <Switch checked={v} unCheckedChildren="否" checkedChildren="是" autoWidth />,
    },
  },
  pendingSettlementAmount: {
    label: '待分账金额',
    text: (v) => <span>{(v / 100).toFixed(2)}</span>,
  },
  settledAmount: {
    label: '已分账金额（单位：分）',
  },
  refundedAmount: {
    label: '已退款金额',
  },
  contributionAmount: {
    label: '本次退款出资金额',
    ui: {
      renderer: (v) => <span>{v / 100}</span>,
    },
  },
  refundPrice: {
    label: '退款金额',
  },
  ticketRefunds: [{
    label: '该出资方涵盖车票及对应金额',
    ticketCode: {
      label: '车票号',
    },
    refundPrice: {
      label: '退款金额',
    },
  }],
  targetType: {
    label: '帐户类型<br/> 由调用方根据分账方身份类型定义，例如：COMPANY,PARTNER,CHANNEL等',
  },
  targetId: {
    label: 'targetType下的帐户标识',
  },
  targetName: {
    label: '帐户名',
  },
  refundPrice: {
    label: t`申请退款金额`,
    ui: {
      renderer: (v) => <Input readOnly={rootStore.rsOrderStore._orderRefundStatus === '0'} value={v} />,
      itemProps: { required: true },
    },
  },
  refundRemark: {
    label: t`申请退款说明`,
    ui: {
      renderer: (v) => <Input.TextArea value={v} />,
    },
  },
  refundTime: {
    label: t`实际退款时间`,
    text: DATETIME_TEXT,
    ui: {
      renderer: (v) => <DatePicker style={{ width: '100%' }} type="datetime" showTime value={v} />,
    },
  },
  distanceTime: {
    label: t`距离发车时长`,
    ui: {
      renderer: (v) => <span style={{ color: 'blue', fontWeight: 450, fontSize: 15 }}>{v}</span>,
    },
  },
  cancelTime: {
    label: t`申请取消时间`,
    text: DATETIME_TEXT,
    ui: {
      renderer: (v) => <DatePicker2 style={{ width: '100%' }} outputFormat={DATETIME_TEXT} showTime value={v} />,
      itemProps: { required: true },
    },
  },
  orderCommentCount: {
    label: t`订单评价数量`,
  },
  partnerName: {
    label: t`合伙人名称`,
  },
  portTypeName: {
    label: t`口岸名称`,
  },
  orderStatusName: {
    label: t`订单状态，0 - 未支付；1 - 已支付； 2 - 已派车；3 - 已确定；4 - 已开始；5 - 已完成；6 - 已取消（支付超时如何处理？保留还是删除？）；7 -已出发`,
  },
  startMainAreaName: {
    label: t`开始城市名称`,
  },
  endMainAreaName: {
    label: t`结束城市名称`,
  },
  startMinorAreaName: {
    label: t`开始区域名称`,
  },
  endMinorAreaName: {
    label: t`结束区域名称`,
  },
  writeOffUserName: {
    label: t`核销人名称`,
  },
  operatingCompanyName: {
    label: t`运营公司名称`,
  },
  companyName: {
    label: t`承运公司名称`,
  },
  orderNumber: {
    label: t`订单编号`,
  },
  hotel: {
    label: t`关联酒店`,
  },
  hotelPrice: {
    label: t`酒店价格`,
  },
  hotelRootPrice: {
    label: t`酒店基础价`,
  },
  taskIds: [{
    label: t`任务关联id`,
  }],
  completionTime: {
    label: t`完成时间`,
  },
  orderChangeRemarks: {
    label: t`订单变更备注`,
  },
  username: {
    label: t`操作人账号`,
  },
  attachments: [{
    label: t`附件`,
    title: {
      label: t`附件标题`,
    },
    description: {
      label: t`附件说明`,
    },
    binaryId: [{
      label: t`附件id`,
    }],
  }],
  rsOrder: {
    label: t`拼车订单`,
    orderNo: {
      label: t`订单编号，自动生成，规则：CCOYYYYMMDDHHMMSS+3位数字`,
    },
    operatingOrderId: {
      label: t`运营公司订单id`,
    },
    operatingCompanyId: {
      label: t`运营公司id`,
    },
    companyId: {
      label: t`公司id`,
    },
    dailySettleId: {
      label: t`日结Id`,
    },
    monthlySettleId: {
      label: t`月结Id`,
    },
    linkRoutePrice: {
      label: t`关联线路价格`,
    },
    orderStatus: {
      label: t`订单状态 0-已取消 1-已支付 2-已完成 3-其他`,
    },
    partnerId: {
      label: t`合伙人id`,
    },
    orderFromType: {
      label: t`订单来源 0 - 微信 , 1 - 后台下单`,
    },
    rootPrice: {
      label: t`线路基础价`,
    },
    payType: {
      label: t`支付方式，0 - 微信支付 , 1 - 支付宝`,
    },
    appId: {
      label: t`appid`,
    },
    payTime: {
      label: t`支付时间`,
    },
    refundTime: {
      label: t`退款时间`,
    },
    cancelOrderTime: {
      label: t`取消订单时间`,
    },
    cancelRemark: {
      label: t`取消订单备注`,
    },
    refundPrice: {
      label: t`退款金额`,
    },
    refundStatus: {
      label: t`退款状态，0 - 未退款；1 - 已退款`,
    },
    refundRemark: {
      label: t`退款备注`,
    },
    ticketInfo: {
      label: t`车票信息`,
      operatingTicketCode: {
        label: t`运营公司车票号`,
      },
      operatingTakeTicketCode: {
        label: t`运营公司取票号`,
      },
      ticketPrice: {
        label: t`票价`,
      },
      refundPrice: {
        label: t`车票退款金额`,
      },
      serviceCharge: {
        label: t`手续费`,
      },
      firstChangePrice: {
        label: t`真实优惠`,
      },
      operatingTicketPrice: {
        label: t`运营公司票价`,
      },
      writeOff: {
        label: t`0：未核销,1：已核销`,
      },
      writeOffUser: {
        label: t`核销人`,
      },
      writeOffDate: {
        label: t`核销时间`,
      },
      //  0-状态未知 1-新票未售 2-已售未取 3-已取未用<br/> 5-已乘车扫描未转乘 6-已扫描 7-车票已过期 8-车票已停用 9-车票已作废 10-已退票
      operatingState: {
        label: t`中港通状态`,
      },
      //  0-已取消 1-未乘车 2-已乘车 3-已完成 4-其他 5-已过期
      state: {
        label: t`状态`,
        text: (v) => ENUMS.ticketStatus[v],
      },
      ignore: {
        label: t`是否忽略<br/> - false 不忽略，不在申请退款中且中港通已退款则会显示在申请取消列表中<br/> - true 忽略`,
      },
      stateName: {
        label: t`状态名称`,
      },
      ticketCode: {
        label: t`车票号`,
      },
      takeTicketCode: {
        label: t`取票号`,
      },
      seats: {
        label: t`座位号`,
      },
      cancelTime: {
        label: t`客户申请取消时间`,
      },
      originalPrice: {
        label: t`原票价`,
      },
      account: {
        label: '分账方信息',
      },
    },
    shiftTime: {
      label: t`班次时间`,
    },
    remarks: {
      label: t`备注信息`,
    },
    consoleRemarks: {
      label: t`控制台备注信息`,
    },
    flightNumber: {
      label: t`航班号`,
    },
    orderType: {
      label: t`订单类型，0 - 点对点；1 - 时租`,
    },
    vehicleId: {
      label: t`车辆id`,
    },
    driverId: {
      label: t`司机id`,
    },
    driverName: {
      label: t`司机名`,
    },
    language: [{
      label: t`语言要求`,
    }],
    passengerName: {
      label: t`乘坐人`,
    },
    passengerPhone: {
      label: t`乘坐人电话`,
    },
    subscribeName: {
      label: t`预约人`,
    },
    subscribePhone: {
      label: t`预约人电话`,
    },
    number: {
      label: t`人数`,
    },
    numberOfLuggage: {
      label: t`行李数`,
    },
    startMainArea: {
      label: t`开始城市编号`,
    },
    startMinorArea: {
      label: t`开始区域编号`,
    },
    startStationName: {
      label: t`开始站点名称`,
    },
    endMainArea: {
      label: t`结束城市编号`,
    },
    endMinorArea: {
      label: t`结束区域编号`,
    },
    endStationName: {
      label: t`结束站点名称`,
    },
    predictBeginDate: {
      label: t`预估开始时间`,
    },
    predictEndDate: {
      label: t`预估结束时间`,
    },
    isPass: {
      label: t`是否过关`,
    },
    portType: {
      label: t`口岸类型，0 - 深圳湾口岸；1 - 澳门口岸；2 - 珠海口岸`,
    },
    isMap: {
      label: t`需要地图链接`,
    },
    predictTime: {
      label: t`预估时长`,
    },
    mileage: {
      label: t`里程`,
    },
    beginName: {
      label: t`开始地址`,
    },
    beginTude: {
      label: t`开始地址经纬度`,
    },
    endName: {
      label: t`结束地址`,
    },
    endTude: {
      label: t`结束地址经纬度`,
    },
    surcharges: [{
      label: t`附加费列表`,
    }],
    roadFee: {
      label: t`路桥费`,
    },
    oilFee: {
      label: t`加油费`,
    },
    partFee: {
      label: t`停车费`,
    },
    repairFee: {
      label: t`维修费`,
    },
    otherFee: {
      label: t`其他费用`,
    },
    surchargeExplain: {
      label: t`附加费说明`,
    },
    addFee: {
      label: t`附加总费用`,
    },
    surchargePayStatus: {
      label: t`附加费支付状态，0 - 未支付；1 - 已支付；`,
    },
    surchargePayUrl: {
      label: t`附加费微信支付地址`,
    },
  },
  transactionId: {
    label: t`微信支付订单号`,
  },
  prepayId: {
    label: t`微信预支付生成的标识<br/> 首次发起支付时生成，支付过程中断后再次支付时提供`,
  },
  price: {
    label: t`订单对外销售价格`,
  },
  originalPrice: {
    label: t`订单原价`,
    ui: {
      renderer: (v) => <span>{v}</span>,
    },
  },
  currency: {
    label: t`币种<br/> - RMB<br/> - HKD<br/> - MOP`,
  },
  orderType: {
    label: t`订单类型<br/> - 1 包车订单<br/> - 2 班车订单<br/> - 3 巴士订单`,
  },
  relation: {
    label: t`关联订单<br/> 记录发起返空线路的原订单。不为空则表示为特惠订单。`,
  },
  notices: [{
    label: t`通知控制信息<br/> 第二次将不发送通知`,
  }],
  settlementId: {
    label: t`结算id`,
  },
  unfrozenFunds: {
    label: t`是否解冻资金`,
  },
  closingOfDistribution: {
    label: t`是否分账结束`,
  },
  accountRequestInfos: [{
    label: t`分账请求信息列表`,
    appId: {
      label: t`appId`,
    },
    id: {
      label: t`订单id`,
    },
    transactionId: {
      label: t`微信支付订单号`,
    },
    outOrderNo: {
      label: t`商户系统内部的分账单号`,
    },
    orderId: {
      label: t`微信分账单号,微信支付系统返回的唯一标识`,
    },
    state: {
      label: t`分账单状态（每个接收方的分账结果请查看receivers中的result字段）<br/> 1、PROCESSING：处理中<br/> 2、FINISHED：分账完成`,
    },
    receivers: [{
      label: t`分账方信息列表`,
      type: {
        label: t`分账接收方类型<br/> 1、MERCHANT_ID：商户号<br/> 2、PERSONAL_OPENID：个人openid（由父商户APPID转换得到）`,
      },
      description: {
        label: t`分账的原因描述，分账账单中需要体现`,
      },
      account: {
        label: t`分账接收方账号：<br/> 1、类型是MERCHANT_ID时，是商户号（mch_id或者sub_mch_id）<br/> 2、类型是PERSONAL_OPENID时，是个人openid`,
      },
      username: {
        label: t`合伙人 / 公司 / 司机`,
      },
      name: {
        label: t`合伙人名 / 公司名 / 司机`,
      },
      userType: {
        label: t`身份 1-合伙人 2-公司 3-司机`,
      },
      amount: {
        label: t`分账金额 单位为分，只能为整数，不能超过原订单支付金额及最大分账比例金额`,
      },
      result: {
        label: t`分账结果<br/> 1、PENDING：待分账<br/> 2、SUCCESS：分账成功<br/> 3、CLOSED：已关闭`,
      },
      failReason: {
        label: t`分账失败原因，当分账结果result为CLOSED（已关闭）时，返回该字段<br/> 1、ACCOUNT_ABNORMAL：分账接收账户异常<br/> 2、NO_RELATION：分账关系已解除<br/> 3、RECEIVER_HIGH_RISK：高风险接收方<br/> 4、RECEIVER_REAL_NAME_NOT_VERIFIED：接收方未实名<br/> 5、NO_AUTH：分账权限已解除<br/> 6、RECEIVER_RECEIPT_LIMIT：接收方已达收款限额<br/> 7、PAYER_ACCOUNT_ABNORMAL：分出方账户异常`,
      },
      detailId: {
        label: t`微信分账明细单号`,
      },
      inflowPlatform: {
        label: t`这笔资金是否放回平台`,
      },
      redistribute: {
        label: t`重新分账信息`,
        outOrderNo: {
          label: t`商户系统内部的分账单号`,
        },
        orderId: {
          label: t`微信分账单号,微信支付系统返回的唯一标识`,
        },
        state: {
          label: t`分账单状态（每个接收方的分账结果请查看receivers中的result字段）<br/> 1、PROCESSING：处理中<br/> 2、FINISHED：分账完成`,
        },
        result: {
          label: t`分账结果<br/> 1、PENDING：待分账<br/> 2、SUCCESS：分账成功<br/> 3、CLOSED：已关闭`,
        },
        failReason: {
          label: t`分账失败原因，当分账结果result为CLOSED（已关闭）时，返回该字段`,
        },
        detailId: {
          label: t`微信分账明细单号`,
        },
      },
    }],
  }],
  refundInfos: [{
    label: t`退款信息集合`,
    applicationId: {
      label: t`申请编号<br/> S + 年月日 + 自增编号`,
    },
    state: {
      label: t`申请状态<br/> - 0 已驳回<br/> - 1 申请中<br/> - 2 已提交<br/> 前端提交`,
    },
    refundId: {
      label: t`退款流水号`,
    },
    type: {
      label: t`退款类型<br/> - 0 车票类型<br/> - 1 取消订单<br/> - 2 其他类型`,
    },
    distanceTime: {
      label: t`距离时间`,
    },
    cancelTime: {
      label: t`申请取消时间`,
      text: DATETIME_TEXT,
      ui: {
        renderer: (v) => <DatePicker2 style={{ width: '100%' }} outputFormat={DATETIME_TEXT} showTime value={v} />,
      },
    },
    refundPrice: {
      label: t`申请退款金额`,
    },
    cancelRemark: {
      label: t`申请说明`,
    },
    rejectRemark: {
      label: t`驳回说明`,
    },
    rejectTime: {
      label: t`驳回时间`,
    },
    attachments: [{
      label: t`附件`,
      title: {
        label: t`附件标题`,
      },
      description: {
        label: t`附件说明`,
      },
      binaryId: [{
        label: t`附件id`,
      }],
    }],
    ticketRefundInfos: [{
      label: t`车票退款信息`,
      ticketCode: {
        label: t`车票号`,
      },
      originalPrice: {
        label: t`原票价`,
      },
      operatingState: {
        label: t`中港通状态`,
      },
      state: {
        label: t`车票状态`,
      },
      refundPrice: {
        label: t`退款金额`,
      },
      operatorRefundTime: {
        label: t`运营商退款时间`,
      },
    }],
  }],
  crBy: {
    label: t`创建者`,
  },
  upBy: {
    label: t`最后修改者`,
  },
  crDate: {
    label: t`创建时间`,
  },
  upDate: {
    label: t`最后修收时间`,
  },
  tenantId: {
    label: t`租户ID`,
  },
  beginAreaName: {
    label: t`获取开始范围的字符串`,
  },
  endAreaName: {
    label: t`获取结束范围的字符串`,
  },
  id: {
    label: '',
  },
  applicationId: {
    label: t`申请编号`,
  },
  // <br/> - 0 已驳回<br/> - 1 申请中<br/> - 2 已提交<br/> 前端提交
  state: {
    label: t`申请状态`,
    text: (v) => ENUMS.state[v],
  },
  refundId: {
    label: t`退款流水号`,
  },
  // <br/> - 0 车票类型<br/> - 1 取消订单<br/> - 2 其他类型
  type: {
    label: t`退款类型`,
    text: (v) => ENUMS.type[v],
  },
  refunded: {
    label: t`是否退款<br/> - false 未退款<br/> - true 已退款`,
  },
  cancelRemark: {
    label: t`申请说明`,
    ui: {
      renderer: (v) => <Input.TextArea value={v} />,
      span: 2,
    },
  },
  rejectRemark: {
    label: t`驳回说明`,
  },
  rejectTime: {
    label: t`驳回时间`,
  },
  orderInfo: {
    label: t`关联订单信息`,
    orderId: {
      label: t`订单id`,
    },
    orderType: {
      label: t`订单类型：1-包车订单 2-班车订单 3-巴士订单`,
    },
    orderTime: {
      label: t`出行时间`,
    },
    name: {
      label: t`下单人名称`,
    },
  },
  ticketRefundInfos: [{
    label: t`车票退款信息`,
    ticketCode: {
      label: t`车票号`,
    },
    isReturn: {
      label: t`是否回程 0：去程，1：回程`,
    },
    originalPrice: {
      label: t`原票价`,
    },
    operatingState: {
      label: t`中港通状态`,
    },
    state: {
      label: t`车票状态`,
    },
    refundPrice: {
      label: t`退款金额`,
    },
    operatorRefundPrice: {
      label: t`中港通退款金额`,
    },
    operatorRefundTime: {
      label: t`运营商退款时间`,
    },
  }],
};
